package com.hsh.server.common.exception;

import com.hsh.server.constant.CustomException;
import com.hsh.server.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description
 * @Author:
 * @date 2024/5/17 14:22
 */
@Slf4j
@RestControllerAdvice
@SuppressWarnings("ALL")
public class HandelAccessException {

    @ExceptionHandler(CustomException.class)
    public R handleAccessDeniedException(CustomException e,
                                         HttpServletRequest request) {
        String requestURI = request.getRequestURI();
        log.error("请求地址{},权限校验失败{}", requestURI, e.getMessage());
        return R.error(e.getCode(), e.getMessage());
    }
}
